'use strict';

class HttpException extends Error {
  constructor(msg, errorCode, code) {
    super();
    this.errorCode = errorCode || 10001;
    this.code = code || 504;
    this.msg = msg || '服务器异常';
  }
}

class Success extends HttpException {
  constructor(msg, errorCode) {
    super();
    this.code = 200;
    this.msg = msg || 'ok';
    this.errorCode = errorCode || 0;
  }
}

class ParameterException extends HttpException {
  constructor(msg, errorCode) {
    super();
    this.code = 400;
    this.msg = msg || '参数错误';
    this.errorCode = errorCode || 10006;
  }
}

class NotFound extends HttpException {
  constructor(msg, errorCode) {
    super();
    this.msg = msg || '资源未找到';
    this.errorCode = errorCode || 10006;
    this.code = 404;
  }
}

class AuthFailed extends HttpException {
  constructor(msg, errorCode) {
    super();
    this.msg = msg || '授权失败';
    this.errorCode = errorCode || 10005;
    this.code = 401;
  }
}

class Forbbiden extends HttpException {
  constructor(msg, errorCode) {
    super();
    this.msg = msg || '禁止访问';
    this.errorCode = errorCode || 10002;
    this.code = 403;
  }
}

module.exports = {
  HttpException,
  ParameterException,
  Success,
  NotFound,
  AuthFailed,
  Forbbiden,
};
